package com.example.design_pattern.visitor;

import java.util.ArrayList;
import java.util.List;

public abstract class Composite implements Equipment {

    private List<Equipment> mParts;

    public Composite(){
        mParts = new ArrayList<>();
    }

    public void add(Equipment equipment){
        mParts.add(equipment);
    }

    /**
     * 返回价格
     */
    @Override
    public double price() {
        double tmp = 0;
        for(int i = 0; i < mParts.size(); i++){
            tmp += mParts.get(i).price();
        }
        return tmp;
    }

    /**
     * 接收访问者
     *
     * @param visitor
     */
    @Override
    public void accept(Visitor visitor) {

    }
}
